## 定义一个装饰器,记录函数执行的时间
import time
def log_time(func):
    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        ## {func.__name__} 是用来获取函数名
        print(f"执行耗时：{func.__name__}: {end_time - start_time:.4f} 秒")
        return result
    return wrapper

@log_time
def slow_function():
    time.sleep(2)
    print("任务已完成！")

slow_function()